<template>
  <div class="todo-footer" v-show="allNum">
    <label>
<!--      <input type="checkbox" @change="changeAll" :checked="isAll"/>-->
      <input type="checkbox" v-model="isAll"/>
    </label>
    <span>
          <span>已完成{{doneTotalNum}}</span> / 全部{{allNum}}
        </span>
    <button class="btn btn-danger" @click="deleteAlldone">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: "MyFooter",
  props: ['todos'],
  data() {
    return {
    }
  },
  computed: {
    isAll:{
      get() {
        return this.allNum === this.doneTotalNum && this.allNum > 0
      },
      set(value) {
        this.$emit('changeTodoListAll',value)
      }

    },
    allNum() {
      return this.todos.length
    },
    doneTotalNum() {
      return this.todos.reduce((pre, cur)=>{
        console.log('@',pre,cur)
        return pre + (cur.done ? 1 : 0)
      },0)
    }
  },
  methods: {
    /*changeAll(e) {
      console.log('changeAll',e.target.checked)
      this.$emit('changeTodoListAll',e.target.checked)
    },*/
    deleteAlldone() {
      this.$emit('deleteAlldoneItem');
    }
  }
}
</script>

<style scoped>

/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>